home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / morse / staton / voc2bin.c < prev    next >
C/C++ Source or Header  |  1994-04-21  |  3KB  |  109 lines

  1. /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  2. /*  Copyright (C) 1994 Ken Staton  */
  3. /*      All Rights Reserved        */
  4. /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
  5.  
  6. /* 
  7. ** This program strips the header off a SoundBlaster *.VOC
  8. ** file.  It only works with files that were recorded in mono
  9. ** using 8 bit uncompressed format.
  10. **
  11. ** The file format was empirically determined by using 
  12. ** Creative Labs' VOC-HDR.EXE with known binary files.
  13. ** 
  14. ** There is a 32 byte header prepended to the binary data,
  15. ** and a 4 byte terminator (= 0) appended to the data.
  16. */             
  17.  
  18.  
  19. #include <stdio.h> 
  20. #include <stdlib.h>
  21. #include <string.h> 
  22. #include <io.h>
  23.                 
  24. FILE *infile, *outfile;
  25. char sf[255],tf[255];
  26.                 
  27. void main(argc,argv)
  28. int argc;
  29. char *argv[];
  30. {               
  31. int numclosed; 
  32. unsigned int i;
  33. unsigned char b1,b2,b3,b4,b5;
  34. char response;     
  35.  
  36. _wabout("Converts *.VOC files to *.BIN.\nCopyright (C) 1994 Ken Staton.\nAll Rights Reserved.\n");   
  37.  
  38.  
  39. if (argc != 3)
  40.   {
  41.   printf("Enter the source file: \n");
  42.   scanf("%s",sf);
  43.   printf("Enter the target file: \n");
  44.   scanf("%s",tf);
  45.   }
  46. else
  47.   {
  48.   strcpy(sf,argv[1]);
  49.   strcpy(tf,argv[2]); 
  50.   _wsetexit(_WINEXITNOPERSIST);    /* assume no persistence */
  51.   }  
  52.  
  53.    
  54. /* Open for read (will fail if source file does not exist) */
  55. if( (infile  = fopen( sf, "rb" )) == NULL )
  56.   printf( "The file %s was not opened\n",sf );
  57. else
  58.   printf( "The file %s was opened\n",sf );
  59.  
  60. /* Open for write */
  61. /* test for overwrite! */
  62. if( (outfile = fopen( tf, "rb")) != NULL)
  63.   {
  64.   printf("%s Exists!  OVERWRITE (y/n)?",tf);
  65.   scanf("%s",&response);
  66.   if ((response!='Y') && (response!='y')) exit(-1);
  67.   if( fclose( outfile ) ) printf( "The file %s was not closed\n",tf );  
  68.   printf("\n\n");
  69.   }  
  70.   
  71. if( (outfile = fopen( tf, "w+b" )) == NULL )
  72.   printf( "The file %s was not opened\n",tf );
  73. else
  74.   printf( "The file %s was opened\n",tf );
  75.  
  76. /* 
  77. ** Now process .VOC file 
  78. */
  79.    
  80. b1=getc(infile);    /* look ahead to keep from outputting    */
  81. b2=getc(infile);    /* any of the null terminators             */
  82. b3=getc(infile);    /* appended to the *.VOC file            */
  83. b4=getc(infile);
  84. b5=getc(infile);   
  85. i=0; /* count from b1, since this is what is output */
  86. while ( (feof(infile) == 0) ) 
  87.   {  
  88.   if (i>=32)    /* don't output the 1st 32 bytes (header) */
  89.     {  
  90.     putc(b1,outfile); 
  91.     }
  92.   b1=b2;            /* terminating null #1 */
  93.   b2=b3;            /* terminating null #2 */
  94.   b3=b4;            /* terminating null #3 */
  95.   b4=b5;            /* terminating null #4 */
  96.   b5=getc(infile);    /* read past end of file sets EOF) */
  97.   i++;
  98.   } 
  99.  
  100.    
  101. /* Close stream */
  102. if( fclose( infile ) )
  103.   printf( "The file %s was not closed\n",sf );
  104. /* All other files are closed: */
  105. numclosed = _fcloseall( );
  106. printf( "Number of files closed: %u\n", numclosed );
  107.  
  108. }
  109.